package com.steak.concurrent.CompletableFuture.api.call;

import io.netty.util.Timeout;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

/**
 * @author 刘牌
 * @Title:
 * @date 2022-04-2313:33
 */
public class Or {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<Integer> completedFuture = CompletableFuture.supplyAsync(() -> {
            try {
                TimeUnit.SECONDS.sleep(3);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return 100;
        });
        //applyToEitherAsync有返回值
        CompletableFuture<Integer> future = CompletableFuture.supplyAsync(() -> 100)
                .applyToEitherAsync(completedFuture, s -> {
                    System.out.println("123");
                    return s;
                });
        System.out.println(future.get());

        //acceptEitherAsync无返回值
        CompletableFuture<Void> eitherAsync = CompletableFuture.supplyAsync(() -> 100).acceptEitherAsync(completedFuture, System.out::println);
    }
}
